<template>
  <div>
    <el-col :span="24" class="header">
      <div>最近一次更新时间 {{update_at}}</div>
    </el-col>
    <editor v-model="addContent" v-if="editorShow"></editor>
    <el-col :span="24" class="btn">
      <el-button type="primary" size="primary" @click="setExchangeRule">发布</el-button>
    </el-col>
  </div>
</template>

<script>
  import editor from '@/components/editor';
  export default {
    name: "record_rule",
    components: {editor},
    data(){
      return{
        addContent:'这是规则说明',
        editorShow: true,
        update_at: ''
      }
    },
    mounted(){
      this.getExchangeRule()
    },
    methods:{
      //获取兑换规则
      async getExchangeRule(){
        const res = await this.$api.getExchangeRule();
        if (res.data.level == 'success'){
          this.addContent = res.data.data.content;
          this.update_at = res.data.data.updated_at
        }
      },
      //设置兑换规则
      async setExchangeRule(){
        const res = await this.$api.setExchangeRule({content: this.addContent})
        if (res.data.level == 'success'){
          this.$message({
            type: 'success',
            message: res.data.message
          });
          this.getExchangeRule();
        } else {
          this.$message({
            type: 'warning',
            message: res.data.message
          });
        }
      }
    }
  }
</script>

<style scoped>

</style>
